package com.homework;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CompletableFuture03 {
    public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();

        System.out.println("Main Thread Start!");

        ExecutorService executorService = Executors.newCachedThreadPool();

        final CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "123456";
        }, executorService);

        System.out.println("异步处理结果为：" + future.get());

        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");

        executorService.shutdown();
        System.out.println("Main Thread End!");
    }
}
